package xyz.hubery.model;

import xyz.hubery.domain.Order;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * 价格相同的委托单列表
 */
public class MergeOrder {

    private LinkedList<Order> orders = new LinkedList<Order>();

    // 添加订单
    public void add(Order order){
        orders.addLast(order);
    }

    // 获取订单
    public Order get() {
        return orders.get(0);
    }

    public int size() {
        return orders.size();
    }


    public BigDecimal getPrice() {
        return orders.get(0).getPrice();
    }


    public Iterator<Order> iterator() {
        return orders.iterator();
    }

    public BigDecimal getTotalAmount() {
        BigDecimal total = BigDecimal.ZERO;
        for (Order order : orders) {
            total.add(order.getPrice());
        }
        return total;
    }

}
